package com.jigar;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class SimpleServlet extends HttpServlet{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		//super.doGet(req, resp);
		processrequest(req, resp);
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		//super.doPost(req, resp);
		processrequest(req, resp);
	}
	
	void processrequest(HttpServletRequest req, HttpServletResponse resp){
		try {
			resp.setContentType("text/html");
			PrintWriter out= resp.getWriter();
			out.println("<h1>it's from servlet</h1>");
			out.println("printing db detail");
			EmployeeSearch es=new EmployeeSearch();
			List l = es.listEmployees();
			if(l!=null){
			Iterator i= l.iterator();
			while(i.hasNext()){
				out.println(i.next()+"<br/>");
			}
			}
			else{
				System.out.println("data is null");
			}
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

}
